//
//  StatusToolBar.swift
//  swiftImitationWeibo
//
//  Created by 杨果果 on 16/7/13.
//  Copyright © 2016年 yang. All rights reserved.
//

import UIKit

class StatusToolBar: UIView {

    //转发
    private lazy var retweetButton: UIButton = self.addChildButton("timeline_icon_retweet", title: "转发")
    //评论
    private lazy var commentButton: UIButton = self.addChildButton("timeline_icon_comment", title: "评论")
    //赞
    private lazy var unlikeButton: UIButton = self.addChildButton("timeline_icon_unlike", title: "赞")
    var statuesViewModel: StatueViewModel? {
        didSet {


            retweetButton.setTitle(statuesViewModel?.retweetStr, forState: .Normal)
            commentButton.setTitle(statuesViewModel?.commentStr, forState: .Normal)
            unlikeButton.setTitle(statuesViewModel?.unlikeStr, forState: .Normal)
            
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    
    }
    private func setupUI() {
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
            
        }
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        //添加线
        let fristLine = addChildLine()
        let secontLine = addChildLine()
        fristLine.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self.snp_centerY)
            
        }
        
        secontLine.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self.snp_centerY)
            
        }
        
        
    }
    private func addChildLine() -> UIImageView {
        let ImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(ImageView)
        return ImageView
    }
    
    
    
    private func addChildButton(imageName: String, title: String) -> UIButton {
    let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        //取消高亮
        button.adjustsImageWhenHighlighted = false
        //设置文字
        button.setTitle(title, forState: .Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(13)
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        addSubview(button)
        return button
    }
}
